package com.rising.threads.volatiles;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @Author: rising
 * @Description:
 * @Date: create in 2020/12/27 15:11
 */
public class AtomicReferenceTest {

    public static void main(String[] args) {
        Student zs = new Student(1, "张三");
        Student lis = new Student(2, "李四");

        AtomicReference<Student> atomicReference = new AtomicReference<>();
        atomicReference.set(zs);

        System.out.println(atomicReference.compareAndSet(zs, lis) + "\t" + atomicReference.get());
        System.out.println(atomicReference.compareAndSet(zs, lis) + "\t" + atomicReference.get());
        lis.setName("李四2");
        System.out.println(atomicReference.compareAndSet(lis, lis) + "\t" + atomicReference.get());

        AtomicInteger atomicInteger = new AtomicInteger();
        System.out.println(atomicInteger);
        System.out.println(atomicInteger.get());
    }

}

